/*****************************************************************
 * this program performs that it prints a triangle with
 * height=dimension and bottom=2*dimension-1,where dimension is
 * a integer number input in the terminal.
 * for example,dimension = 5,
 *
 *			*
 *		   ***
 *		  *****
 *		 *******
 *		*********
 *
 * date:	2015|11|23
 * author:	laishaofa@gmail.com
 *****************************************************************/

#include <stdio.h>

void printTriangle(int dimension);
void printCircle(int radius);
void printArray();

int main(void)
{
	int dimension = 0;
	int x = 0;
	int y = 0;

	/* step 1.get user's dimension of triangle */
	/* note: dimension of triangle should be poistive and below 11. */
	/*       if not, input angain.*/
	do
	{
		printf("Input Dimension:");
		scanf("%d", &dimension);
		if (dimension <= 0)
		{
			printf("Dimension must be a positive number! Please Try again!\n");
			continue;
		}
		if (dimension > 100)
		{
			printf("Dimension is two large!(<=10)\n");
			continue;
		}
		break;
	}while (1);

	/* step 2.print stars in the interesting area and blank space out of that area */
	printTriangle(dimension);

	printCircle(dimension);

	return 0;
}

void printTriangle(int dimension)
{
	int x = 0;
	int y = 0;

	for (y = 0; y < dimension; y++)
	{
		for (x = 0; x <2 * dimension - 1; x++)
		{
			if (y >= -x + dimension - 1 && y >= x - (dimension - 1))
				printf("*");
			else
				printf(" ");
		}
		printf("\n");
	}
}
void printCircle(int radius)
{
	int x = 0;
	int y = 0;
	for (y = 0; y < radius * 2 + 1; y++)
	{
		for (x = 0; x < radius * 2 + 1; x++)
		{
			if ((x - radius)*(x - radius) + 4 * (y - radius)*(y - radius) <= radius*radius)
				printf("*");
			else
				printf(" ");
		}
		printf("\n");
	}
}
